Total Complexity | 8 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import InvalidInputError from './InvalidInputError'; |
||
3 | export default class Helper { |
||
4 | static dec2bin(number, propositions) { |
||
5 | 15 | if (!Number.isInteger(number)) { |
|
6 | 6 | throw new InvalidInputError(number, 'number isnt a number'); |
|
7 | } |
||
8 | |||
9 | 9 | if (!Number.isInteger(propositions)) { |
|
10 | 4 | throw new InvalidInputError( |
|
11 | propositions, |
||
12 | 'propositions isnt a number' |
||
13 | ); |
||
14 | } |
||
15 | |||
16 | 5 | const binary = parseInt(number, 10).toString(2); |
|
17 | |||
18 | 5 | return binary.padStart(propositions, '0'); |
|
19 | } |
||
20 | |||
21 | static totalTrueInputs(row) { |
||
22 | 133 | if (!Array.isArray(row)) { |
|
23 | 4 | throw new InvalidInputError(row, 'row isnt an array'); |
|
24 | } |
||
25 | |||
26 | 129 | if (row.length < 1) { |
|
27 | 1 | return 0; |
|
28 | } |
||
29 | |||
30 | 128 | return row.reduce( |
|
31 | 288 | (accumulator, currentValue) => accumulator + (currentValue ? 1 : 0) |
|
32 | ); |
||
33 | } |
||
34 | } |
||
35 |